#!/usr/bin/python3
# -*- coding:utf-8 -*-
# __author__ == taoyulong2018@gmail.com
# __time__ == 2023/8/1 9:23
# ===========================================
#       题目名称： 80. 删除有序数组中的重复项 II
#       题目地址： https://leetcode.cn/problems/remove-duplicates-from-sorted-array-ii/
#       题目描述： https://note.youdao.com/s/LWYgPSzT
# ===========================================


class Solution:
    def removeDuplicates(self, nums):
        print(id(nums))
        if len(nums) <= 2:
            return len(nums)
        cur_index = 0
        while cur_index < len(nums) - 2:
            x = nums[cur_index]
            y = nums[cur_index + 1]
            z = nums[cur_index + 2]
            if x == y == z:
                del nums[cur_index]
            else:
                cur_index += 1
        print(id(nums))
        return len(nums)


if __name__ == '__main__':
    s = Solution()
    # 5
    print("nums = [1,1,1,2,2,3] =>", s.removeDuplicates(nums=[1, 1, 1, 2, 2, 3]))
    # 7
    print("nums = [0,0,1,1,1,1,2,3,3] =>", s.removeDuplicates(nums=[0, 0, 1, 1, 1, 1, 2, 3, 3]))
